<?php


/**
 * FilterIterator类可以对元素进行过滤，只要在accept()方法中设置过滤条件就可以了。
 */

class CullingIterator extends FilterIterator
{

	/*** The filteriterator takes  a iterator as param: ***/
	public function __construct( Iterator $it ){
  		parent::__construct( $it );
	}

	/*** check if key is numeric ***/
	function accept(){
 		return is_numeric($this->key());
	}

}

$animals = array('koala', 'kangaroo', 'wombat', 'wallaby', 'emu', 'NZ'=>'kiwi', 'kookaburra', 'platypus');
$cull = new CullingIterator(new ArrayIterator($animals));

foreach($cull as $key => $value) {
	echo $key . ' == ' . $value . '<br />';
}